<html>
<head><meta charset="utf-8"><title>the `?` operator · wg-async-foundations · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/index.html">wg-async-foundations</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html">the `?` operator</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="170577508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170577508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170577508">(Jul 10 2019 at 20:36)</a>:</h4>
<p>I am writing a first pass at reference material for the book. Along the way, I noticed that the async-await RFC says that the <code>?</code> operator's behavior has not yet been determined. And yet it seems to work fine in an async block (<a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=ba95c1f8dfba8f33240a56bfe243ac20" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=ba95c1f8dfba8f33240a56bfe243ac20">playground</a>). Should we move that to a separate feature gate?</p>
<p>cc <span class="user-group-mention" data-user-group-id="1172">@WG-async-foundations</span></p>



<a name="170578201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170578201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170578201">(Jul 10 2019 at 20:44)</a>:</h4>
<p>responded on the issue</p>



<a name="170578223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170578223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170578223">(Jul 10 2019 at 20:44)</a>:</h4>
<p>this was initially a point of discussion</p>



<a name="170578270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170578270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170578270">(Jul 10 2019 at 20:45)</a>:</h4>
<p>but we discussed it in further lang team meetings and decided that we were all okay with <code>return</code>/<code>break</code>/<code>continue</code>/<code>?</code> all working as they did in closures, which is really the only possible option</p>



<a name="170578305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170578305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170578305">(Jul 10 2019 at 20:45)</a>:</h4>
<p>separately feature-gating <code>?</code> would essentially make <code>async</code>/<code>await</code> dead-on-arrival given that almost all futures return <code>Result</code> types.</p>



<a name="170578399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170578399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170578399">(Jul 10 2019 at 20:46)</a>:</h4>
<p>i don't know if that decision was ever recorded anywhere, given that discussion over this has spread across so many issues and meetings over time.</p>



<a name="170578723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170578723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170578723">(Jul 10 2019 at 20:51)</a>:</h4>
<blockquote>
<p>but we discussed it in further lang team meetings and decided that we were all okay with return/break/continue/? all working as they did in closures, which is really the only possible option</p>
</blockquote>
<p>I don't recall this, but I also don't think there's anything strange going on here so I'm fine with shipping it.</p>
<p>That said, looking over the "existing tests" list I see no mention of <code>?</code></p>



<a name="170578859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170578859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170578859">(Jul 10 2019 at 20:53)</a>:</h4>
<p>I mean, I don't think <code>?</code> is "anything special" here-- its behavior falls out as an obvious consequence of async blocks being a kind of closure.</p>



<a name="170578889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170578889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170578889">(Jul 10 2019 at 20:54)</a>:</h4>
<p>but it seems fine to me to add tests for that, break, continue, return, etc.</p>



<a name="170578970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170578970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170578970">(Jul 10 2019 at 20:54)</a>:</h4>
<p>Frankly, that comment should not have been allowed to be added to the RFC</p>



<a name="170578999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170578999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170578999">(Jul 10 2019 at 20:55)</a>:</h4>
<p>There has never been any serious doubt about the behavior of ?</p>



<a name="170579229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170579229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170579229">(Jul 10 2019 at 20:58)</a>:</h4>
<blockquote>
<p>I mean, I don't think ? is "anything special" here-- its behavior falls out as an obvious consequence of async blocks being a kind of closure.</p>
</blockquote>
<p>That presumes a sane compiler and a sane implementation</p>



<a name="170579242"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170579242" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170579242">(Jul 10 2019 at 20:58)</a>:</h4>
<p>I assume the implementation is wrong when thinking of tests</p>



<a name="170579254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170579254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170579254">(Jul 10 2019 at 20:59)</a>:</h4>
<p>and it's also important in terms of avoiding regressions</p>



<a name="170579361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170579361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170579361">(Jul 10 2019 at 21:00)</a>:</h4>
<p>seems like tests for all control flow operatos would be fine</p>



<a name="170579561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170579561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170579561">(Jul 10 2019 at 21:03)</a>:</h4>
<p>(I tested quickly at playground... seems nothing strange is going on, but the one bit that stood out is that <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=42f1c7732a5623674481654189f517ee" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=42f1c7732a5623674481654189f517ee">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=42f1c7732a5623674481654189f517ee</a> gives subpar diagnostics that leaks the fact that it behaves like a function)</p>



<a name="170579572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170579572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170579572">(Jul 10 2019 at 21:03)</a>:</h4>
<p>(That doesn't seem blocking, but it would be good to improve diagnostics here)</p>



<a name="170579870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170579870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170579870">(Jul 10 2019 at 21:08)</a>:</h4>
<p>(Filed as: <a href="https://github.com/rust-lang/rust/issues/62570" target="_blank" title="https://github.com/rust-lang/rust/issues/62570">https://github.com/rust-lang/rust/issues/62570</a>)</p>



<a name="170583254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170583254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170583254">(Jul 10 2019 at 22:02)</a>:</h4>
<p>I agree we should just stabilize existing behavior of <code>?</code></p>



<a name="170583282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170583282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170583282">(Jul 10 2019 at 22:03)</a>:</h4>
<p>I also agree we should write some tests :)</p>



<a name="170583308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170583308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170583308">(Jul 10 2019 at 22:04)</a>:</h4>
<p><span class="user-mention" data-user-id="127859">@Taylor Cramer</span> do we permit <code>return</code> to "return" from the block?</p>



<a name="170583369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170583369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170583369">(Jul 10 2019 at 22:04)</a>:</h4>
<p>it...seems we do.</p>



<a name="170584388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170584388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170584388">(Jul 10 2019 at 22:18)</a>:</h4>
<p>Into where does it return?</p>



<a name="170586027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170586027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170586027">(Jul 10 2019 at 22:44)</a>:</h4>
<p>Into the result of the future, as with a closure.</p>



<a name="170586036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170586036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170586036">(Jul 10 2019 at 22:44)</a>:</h4>
<p>And yes this connects to your other topic :)</p>



<a name="170586051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170586051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> rpjohnst <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170586051">(Jul 10 2019 at 22:44)</a>:</h4>
<p>otoh this makes async blocks into implicit try blocks, in a sense- they're intentionally <em>not</em> like closures in a lot of ways so it seems strange and unnecessary to allow <code>return</code>/<code>?</code> just because the implementation is straightforward</p>



<a name="170586055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170586055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170586055">(Jul 10 2019 at 22:44)</a>:</h4>
<p>/me not inclined to revist a basic question like this at this stage</p>



<a name="170586097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170586097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170586097">(Jul 10 2019 at 22:45)</a>:</h4>
<p>(although I agree that <code>return</code> in particular feels surprising to me)</p>



<a name="170586109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170586109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170586109">(Jul 10 2019 at 22:45)</a>:</h4>
<p>although convenient!</p>



<a name="170711332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/the%20%60%3F%60%20operator/near/170711332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/the.20.60.3F.60.20operator.html#170711332">(Jul 12 2019 at 10:31)</a>:</h4>
<p>i too find it very awkward that <code>return</code> has closure semantic without the closure syntax (the <code>||</code>) :(</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>